package com.xbs.dao.hitchhiking;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.List;import org.eclipse.jdt.internal.compiler.lookup.PackageBinding;

import com.xbs.dao.conn.BaseDao;
import com.xbs.dao.conn.ParamSet;
import com.xbs.dao.conn.RowDatas;
import com.xbs.entity.CommonOrderEntity;
import com.xbs.entity.HitchMoneyAdminEntity;
import com.xbs.entity.HitchOrderAdminEntity;
import com.xbs.entity.TimeEntity;

/**
 * 后台顺风车的顺风车订单管理dao
 */
public class HitchOrderAdminDao extends BaseDao{
	/**
	 * 实例化一个顺风车订单对象
	 */
	private RowDatas<HitchOrderAdminEntity> hitchadmin;
	private RowDatas<CommonOrderEntity> coe;
	private RowDatas<CommonOrderEntity> coe2;
	
	/**
	 * 实例化一个int类型
	 * 
	 */
	private RowDatas<Integer> total;
	
	public HitchOrderAdminDao() {
		hitchadmin = new getHitchAdminData();
		coe = new HitchOrderData();
		coe2 = new HitchOrderData2();
		total = new getTotal();
	}
	
	/**
	 * 1.默认查看当前订单
	 */
	public List<HitchOrderAdminEntity> getHitchOrder(){
		String sql = "select distinct co.co_id,co.co_order_status,"
				+ " co.co_plan_pay_money,co.co_remark,r.rent_name,"
				+ " r.rent_idcard,r.rent_telphone from tb_common_order co,tb_rent r"
				+ " where co.co_id = r.co_id and co.co_order_kind='顺风车'";
		return queryList(sql, hitchadmin);
	}
	
	/**
	 * 2.根据身份证号码，姓名，订单号，电话
	 */
	public List<HitchOrderAdminEntity> getHitchOrderByFour(String str) {
		String sql = "select distinct co.co_id,co.co_order_status,co.co_plan_pay_money,"
				+ " co.co_remark,r.rent_name,r.rent_idcard,r.rent_telphone " + " from tb_common_order co "
						+ " left join tb_rent r on co.co_id = r.co_id "
				+ " where co.co_id like '%" + str + "%' " + "or r.rent_name like '%" + str + "%'  "
				+ " or r.rent_idcard like '%" + str + "%' " + "or r.rent_telphone like '%" + str + "%'";
		System.out.println(sql);
		return queryList(sql, hitchadmin);
	}
	
	/**
	 * 3.取车时对顺风车弹框信息
	 */
	public List<CommonOrderEntity> selOrderByGet(CommonOrderEntity corder){
		
		String sql = "select co_id,co_rent_idcard,co_car_type "
				+ " from tb_common_order co where co.co_id =?";
		
		return queryList(sql, new ParamSet(corder.getCo_id()), coe);
		
	}
	
	/**
	 * 4.取车时，根据订单编号对订单表进行修改
	 */
	public int updateOrderByGet(CommonOrderEntity cde){
		int row = 0;
		String sql = "update tb_common_order "
				+ " set co_card_id=? ,co_car_type=?,"
				+ " co_order_status=?,co_remark=?,"
				+ " co_get_operator=? where co_id =?";
		row = updateExecuted(sql, new ParamSet(cde.getCo_car_id(),
				cde.getCo_car_type(),cde.getCo_order_status(),cde.getCo_remark(),
				cde.getCo_get_operator(),cde.getCo_id()));
		return row;
	}
	/**
	 *5. 取车更改时间表是取车时间
	 */
	public int updateGetTime(TimeEntity te){
		int row = 0;
		String sql = "update tb_time set time_fact_get=? where time_order_id=?";
		row = updateExecuted(sql, new ParamSet(te.getTime_fact_get(),te.getTime_order_id()));
		return row;
	}
	
	/**
	 * 6.还车时对顺风车弹框信息
	 */
	public List<CommonOrderEntity> selOrderByReturn(CommonOrderEntity corder){
		
		String sql = "select co_id,co_rent_idcard"
				+ " from tb_common_order co "
				+ " where co.co_id =?";
		
		return queryList(sql, new ParamSet(corder.getCo_id()), coe2);
	}
	
	/**
	 * 7.还车时，根据订单编号对订单表进行修改
	 */
	public int updateOrderByReturn(HitchMoneyAdminEntity hmae){
		int row = 0;
		String sql = "update tb_common_order cm,tb_order_money om "
				+ " set cm.co_compensation =? ,cm.co_order_status=?, om.order_service_money=?,"
				+ " om.order_car_damage_money=? where cm.co_id = om.order_id and cm.co_id = ?";
		System.out.println(sql);
		row = updateExecuted(sql, new ParamSet(hmae.getCo_compensation(),hmae.getCo_order_status(),
				hmae.getOrder_service_money(),hmae.getOrder_car_damage_money(),
				hmae.getCo_id()));
		return row;
	}
	
	/**
	 *8. 取车更改时间表是取车时间
	 */
	public int updateReturnTime(TimeEntity te){
		int row = 0;
		String sql = "update tb_time set time_fact_return=? where time_order_id=?";
		row = updateExecuted(sql, new ParamSet(te.getTime_fact_return(),te.getTime_order_id()));
		return row;
	}

	
	
	/**
	 * 1.内部类，获取总数记录
	 * @author dell
	 */
	public class getHitchAdminData implements RowDatas<HitchOrderAdminEntity>{

		@Override
		public HitchOrderAdminEntity getRowData(ResultSet rs) throws SQLException {
			HitchOrderAdminEntity hoae = new HitchOrderAdminEntity();
			hoae.setHoid(rs.getString("co_id"));
			hoae.setHoidcard(rs.getString("rent_idcard"));
			hoae.setHomoney(rs.getDouble("co_plan_pay_money"));
			hoae.setHoname(rs.getString("rent_name"));
			hoae.setHostatus(rs.getString("co_order_status"));
			hoae.setHotel(rs.getString("rent_telphone"));
			hoae.setRemark(rs.getString("co_remark"));
			return hoae;
		}
		
	}
	
	/**
	 * 2.在取车时进行操作
	 */
	class HitchOrderData implements RowDatas<CommonOrderEntity>{

		@Override
		public CommonOrderEntity getRowData(ResultSet rs) throws SQLException {
		CommonOrderEntity coe = new CommonOrderEntity();
		coe.setCo_id(rs.getString("co_id"));
		coe.setCo_rent_idcard(rs.getString("co_rent_idcard"));
		coe.setCo_car_type(rs.getString("co_car_type"));
	
		
			return coe;
		}
		
	}
	
	/**
	 * 3.在还车时进行操作
	 */
	
	class HitchOrderData2 implements RowDatas<CommonOrderEntity>{

		@Override
		public CommonOrderEntity getRowData(ResultSet rs) throws SQLException {
		CommonOrderEntity coe2 = new CommonOrderEntity();
		coe2.setCo_id(rs.getString("co_id"));
		coe2.setCo_rent_idcard(rs.getString("co_rent_idcard"));
		
			return coe2;
		}
		
	}
	
	/**
	 * 2.内部类
	 * @author dell
	 */
	public class getTotal implements RowDatas<Integer>{
		@Override
		public Integer getRowData(ResultSet rs) throws SQLException {
			return rs.getInt(1);
		}
	}
}
